<script>
	import {
		ref
	} from 'vue'
	import {
		apiUrl
	} from '@/config/config.js';
	export default {
		data() {
			return {
				form: {
					name: '', // 收货人
					phone: '', // 联系方式
					number: '', // 身份证
					backgroundDisease: '', // 基础病
					userId: '',					
				},
				apiUrl: apiUrl,
				patientId: '',
			}
		},
		onLoad: function(option) {
			// console.log('测试')
			this.patientId = option.id
			// 获取页面数据
			this.getPatient(option.id)
		},
		methods: {
			getPatient(id){
				uni.request({
					url: this.apiUrl + `/api/userPatient/${id}`,
					method: 'GET',
					success: (res) => {
						this.form = res.data.data
					}
				})
			},
			savePatient() {
				// 模拟发送表单数据到后端的操作
				this.form.userId = uni.getStorageSync('account_key')
				uni.request({
					// url: 'http://localhost:8080/api/userPatient/add',
					url: this.apiUrl + '/api/userPatient/edit',
					data: this.form,
					method: 'Post',
					success: (res) => {
						if (res.data.code == '200') {
							uni.showModal({
								content: '修改成功',
							});
							uni.navigateBack({
								delta: 1
							})
						} else {

						}
					}
				})
			},
			toRelation(){
				uni.navigateTo({
					url: '/pages/mine/patient/edit-relation'
				})
			}
		}
	}
</script>



<template>
	<view class="content">
		<form>
			<!-- 表单内容 -->
			<view class="form-item">
				<text class="label">就诊人</text>
				<input class="input" placeholder="请填写就诊人姓名" value="" v-model="form.name" />
			</view>
			<view class="form-item">
				<text class="label">手机号码</text>
				<input class="input" placeholder="请填写联系人手机号码" value="" v-model="form.phone" />
			</view>
			<view class="form-item">
				<text class="label">身份证号</text>
				<input class="input" placeholder="请填写就诊人身份证号" value="" v-model="form.number" />
			</view>
			<view class="form-item">
				<text class="label">既往病史</text>
				<input class="input" placeholder="请完善就诊人既往病史" value="" v-model="form.backgroundDisease" />
			</view>

		</form>

	</view>
	<!-- <view>提示</view> -->
	<view class="content">
		<view class="form-item" @click="toRelation">
			亲友权限>
		</view>
	</view>
	<!-- 提交按钮 -->
	<button class="button" @click="savePatient">保存</button>
</template>

<style lang="scss">
	page {
		background-color: #f4f4f4;
	}

	.content {
		margin: 20rpx 20rpx 0;
		padding: 0 20rpx;
		border-radius: 10rpx;
		background-color: #fff;

		.form-item,
		.uni-forms-item {
			display: flex;
			align-items: center;
			min-height: 96rpx;
			padding: 25rpx 10rpx;
			background-color: #fff;
			font-size: 28rpx;
			border-bottom: 1rpx solid #ddd;
			position: relative;
			margin-bottom: 0;

			// 调整 uni-forms 样式
			.uni-forms-item__content {
				display: flex;
			}

			.uni-forms-item__error {
				margin-left: 200rpx;
			}

			&:last-child {
				border: none;
			}

			.label {
				width: 200rpx;
				color: #333;
			}

			.input {
				flex: 1;
				display: block;
				height: 46rpx;
			}

			.switch {
				position: absolute;
				right: -20rpx;
				transform: scale(0.8);
			}

			.picker {
				flex: 1;
			}

			.placeholder {
				color: #808080;
			}
		}
	}

	.button {
		height: 80rpx;
		margin: 30rpx 20rpx;
		color: #fff;
		border-radius: 80rpx;
		font-size: 30rpx;
		background-color: #27ba9b;
	}
</style>